<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>我来找茬</title>
    <link rel="stylesheet" type="text/css" href="resources/css/ext-all.css" />
    <script type="text/javascript" src="js/ext-base.js"></script>
    <script type="text/javascript" src="js/ext-all.js"></script>
</head>
<body style="padding:10px;">
<div id="north-div"></div>
<div id="center"></div>
<script type="text/javascript">
Ext.onReady(function(){
	//编码方式
	Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8';
	//使用表单提示
	Ext.QuickTips.init();
	Ext.form.Field.prototype.msgTarget = 'side';
    var ds = new Ext.data.Store({//这是数据源
        proxy : new Ext.data.HttpProxy({url:'command/list.action?commType=2'}),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'id'
            },[{
                name:'id'
            },{
                name:'sendType'
            },{
                name:'content'
            },{
                name:'issuer'
            },{
                name:'sender'
            },{
                name:'top'
            },{
                name:'issueTime'
            },{
                name:'sendTime'
            },{
                name:'imgSrc'
            },{
                name:'issuer'
            },{
                name:'sender'
            },{
                name:'deparList'
            },{
                name:'proList'
            },{
                name:'staffList'
            },{
                name:'status'
            },{
                name:'createdAt'
            }])
    });
    var departDS = new Ext.data.Store({//这是数据源
        proxy : new Ext.data.HttpProxy({url:'staff/deprtList.action?loadAll=T'}),
        reader: new Ext.data.JsonReader({
            root:'topics',
            totalProperty: 'totalCount',
            id: 'id'
            },[{name:'id'},{name:'name'}])
    });
    
    var persDS = new Ext.data.Store({//这是数据源
        proxy : new Ext.data.HttpProxy({url:'staff/persList.action?loadAll=T'}),
        reader: new Ext.data.JsonReader({
            root:'topics',
            totalProperty: 'totalCount',
            id: 'id'
            },[{name:'id'},{name:'name'}])
    });
    
    var staffDS = new Ext.data.Store({//这是数据源
        proxy : new Ext.data.HttpProxy({url:'staff/list.action?loadAll=T'}),
        reader: new Ext.data.JsonReader({
            root: 'topics',
            totalProperty: 'totalCount',
            id: 'id'
            },[{
                   name:'id'
               },{
                   name:'name'
               },{
                   name:'mobile'
               },{
                   name:'department'
               },{
                   name:'profession'
               },{
                   name:'special'
               }])
    });

    var replyDS = new Ext.data.Store({//这是数据源
        proxy : new Ext.data.HttpProxy({url:'reply/list.action'}),
        reader: new Ext.data.JsonReader({
            root:'topics',
            totalProperty: 'totalCount',
            id: 'id'
            },[{name:'id'},{name:'content'},{name:'owner'},{name:'command'}])
    });
    
    var colModel = new Ext.grid.ColumnModel([//定义列
         {header:'ID',width:50,sortable:true,dataIndex:'id'},
         {header:'发送类型',width:100,sortable:true,dataIndex:'sendType'},
         {header:'内容', width:400,sortable:true,dataIndex:'content'},
         {header:'签发人',width:100,sortable:true,dataIndex:'issuer',renderer:function(data){return data.name;}},
         {header:'发送人',width:100,sortable:true,dataIndex:'sender',renderer:function(data){return data.name;}},
         {header:'状态',width:100,sortable:true,dataIndex:'status',renderer:function(status){
                if(status=='0'){
                    return '<b style="color:red;">新消息</b>';
                }else if(status=='2'){
                    return '<b style="color:blue;">已安排处理</b>';
                }else if(status=='3'){
                    return '<b style="color:blue;">已处理完毕</b>';
                }else{
                    return '<b style="color:blue;">已转发相关人员</b>';
                }
    	  }},
    	  {header:'查看附件',width:100,sortable:true,dataIndex:'imgSrc',renderer:function(data){
           	 if(data&&data!=""){
               	 return '<input type="button" value="查看附件" onclick="window._showAttDialog(\''+data+'\');"/>';
              }
              return "";
          }},
    	 {header:'发送时间',width:100,sortable:true,dataIndex:'createdAt'},
         {header:'是否置顶',width:100,sortable:true,dataIndex:'top'}
    ]);
    
    var replyColModel = new Ext.grid.ColumnModel([//定义列
         {header:'ID',width:50,sortable:true,dataIndex:'id'},
         {header:'内容', width:100,sortable:true,dataIndex:'content'},
         {header:'回复人姓名',width:100,sortable:true,dataIndex:'owner',renderer:function(data){return data.name;}},
         {header:'回复人电话',width:100,sortable:true,dataIndex:'owner',renderer:function(data){return data.mobile;}}
    ]);

    
    var tb = new Ext.Toolbar('north-div');//创建一个工具条
   
    tb.add({
	        id:'showBtn',
	        text: '查看详情',
	        handler:showUser
        },{
        	id:'replyBtn',
	        text: '查看回复',
	        handler: shwoReply
        },{
	        text: '删除',
	        handler: delUser
    });
 
    var grid = new Ext.grid.GridPanel({//列表
                border:false,
                region:'center',
                loadMask: true,
                el:'center',
                title:'条目列表',
                store: ds,
                cm: colModel,
                autoScroll: true,
                bbar: new Ext.PagingToolbar({
                    pageSize: 20,
                    store: ds,
                    displayInfo: true,
                    displayMsg: '第{0} 到 {1} 条数据 共{2}条',
                    emptyMsg: "没有数据"
                })
   });

    grid.addListener('rowdblclick',rowdblclickFn);
    function rowdblclickFn(grid, rowindex, e){     
	    grid.getSelectionModel().each(function(rec){     
	    	Ext.Msg.alert('信息正文',rec.get('content'));    
	    });     
    }
    
    var replyGrid = new Ext.grid.GridPanel({//列表
                border:false,
                loadMask: true,
                store: replyDS,
                cm: replyColModel,
                autoScroll: true,
                bbar: new Ext.PagingToolbar({
                    pageSize: 20,
                    store: replyDS,
                    displayInfo: true,
                    displayMsg: '第{0} 到 {1} 条数据 共{2}条',
                    emptyMsg: "没有数据"
                })
   });

   var _sel_command_sendType = [['1'﻿,'指挥中心'],
                                ['2','会议信息'],
                                ['3','赛事信息'],
                                ['4','天气信息'],
                                ['5','安保信息'],
                                ['6','交通信息'],
                                ['7','赛场保障'],
                                ['8','应急服务'],
                                ['9','贵宾接待'],
                                ['10','员工信息'],
                                ['11','其他']];
    
    var top = new Ext.FormPanel({//这里是搜索表单
        buttonAlign:'right',
        labelWidth:70,
        region:'north',
        height:100,
        frame:true,
        title: '搜索',
        items: [{
                layout:'column',
                items:[{
                    columnWidth:.25,
                    layout: 'form',
                    items: [{
	        	        xtype:'combo',
                    	hiddenName:'command.sendType',
        		        id:'sel_command_sendType',
	        	        fieldLabel: '发送类别',
	        	        store:{
	            	        xtype:'arraystore',
	    					fields:['id','val'],
	    					data:_sel_command_sendType
	        	         },
	        	        valueField: 'id',
			            displayField:'val',
			            mode: 'local',
			            value:'1',
			            forceSelection:true,
			            typeAhead: true,
			            width:150,
			            triggerAction: 'all'
                    }]
                },{
                    columnWidth:.25,
                    layout: 'form',
                    items: [{
                        xtype:'textfield',
                        fieldLabel: '内容',
                        id: 'sel_command_content',
                        name: 'command.content',
                        anchor:'90%'
                    }]
                },{
                    columnWidth:.25,
                    layout: 'form',
                    items: [{
                    	xtype:'combo',
                    	fieldLabel: '签发人',
                        hiddenName:'command.issuer.id',
                        id:'sel_command_issuer_id',
                        store:staffDS,
                        displayField:'name',
                        valueField:'id',
                        typeAhead: true,
                        forceSelection: true,
                        selectOnFocus:true,
                        mode:'remote',
                        triggerAction: 'all',
                        width:150,
                        emptyText:'请指定签发人...'
                    }]
                },{
                    columnWidth:.25,
                    layout: 'form',
                    items: [{
                    	xtype:'combo',
                    	fieldLabel: '发送人',
                        hiddenName:'command.sender.id',
                        id:'sel_command_sender_id',
                        store:staffDS,
                        displayField:'name',
                        valueField:'id',
                        typeAhead: true,
                        forceSelection: true,
                        selectOnFocus:true,
                        mode:'remote',
                        triggerAction: 'all',
                        width:150,
                        emptyText:'请指定发送人...'
                    }]
                }]
            }
        ],

        buttons: [{
            text: '搜索',
            handler:function(){_loadType = true;loadList();}
        }]
    });
    
    var viewport = new Ext.Viewport({
        layout:'border',
        items:[{
              border:false,
              region:'north',
              contentEl:'north-div',
              tbar:tb,
              height:26
            },{
                layout:"border",
                region:'center',
                border:false,
                items:[top,grid]
                }
        ]}
    );

    
    var loadList = function(){
	    ds.load({params:{start:0, limit:20},callback:function(r,options,success){
		    if(!success){//没取到数据时返回的success=false
		        grid.store.removeAll();//清除原有数据
		        _loadType = false;
		  }
	    }});
    }
    
    loadList();
    var _loadType = false;
    // 这里很关键，如果不加，翻页后搜索条件就变没了，这里的意思是每次数据载入前先把搜索表单值加上去，这样就做到了翻页保留搜索条件了
    ds.on('beforeload',function(){
        Ext.apply(
        this.baseParams,
        {
            'command.sendType':_loadType?Ext.get('sel_command_sendType').dom.value:"",
            'command.content':Ext.get('sel_command_content').dom.value,
            'command.issuer.id':Ext.getCmp('sel_command_issuer_id').getValue(),
            'command.sender.id':Ext.getCmp('sel_command_sender_id').getValue()
        });
    });

    var simple = new Ext.FormPanel({
        id:'addForm',
        name:'addForm',
    	labelWidth:65,
    	width:550,
        frame:true,
        items: [{
	            xtype:'hidden',
	            id:'command_id',
	            name:'command.id'
        	},{
                xtype:'hidden',
                id:'commType',
                name:'commType',
                value:'2'
            },{
        		layout:'column',
        		items:[{
	            		columnWidth:0.5,
	            		layout:'form',
	            		items:{
            		        name:'command.sendType',
            		        id:'command_sendType',
		        	        fieldLabel: '发送类别',
		        	        xtype:'combo',
		        	        store:{
		            	        xtype:'arraystore',
		    					fields:['id','val'],
		    					data:_sel_command_sendType
		        	         },
		        	        valueField: 'id',
				            displayField:'val',
				            mode: 'local',
				            value:'1',
				            forceSelection:true,
				            typeAhead: true,
				            triggerAction: 'all'
            			}
            		},{
	                	columnWidth:0.5,
	                	layout:'form',
	                	items:{
		                	xtype:'checkbox',
		                	name:'command.top',
		                	id:'command_top',
		                	inputValue:'true',
		                	disabled:true,
		                	fieldLabel:'是否置顶'
	                	}
            		}]
	            },{
    				layout:'column',
    				items:[{
						columnWidth:.33,
						layout:'form',
						items:{
			            	xtype:'combo',
			            	fieldLabel: '接收部门',
			                id:'dep_ids',
			                store:departDS,
			                displayField:'name',
			                valueField:'id',
			                hiddenName:'depIds',
			                typeAhead: true,
			                forceSelection: true,
			                selectOnFocus:true,
			                mode:'remote',
			                triggerAction: 'all',
			                listeners : {
								'focus':function(node,event){
							          var p = {};
							          p.vas = Ext.getCmp('dep_ids').getValue();
							          p.ids = Ext.getCmp('dep_ids').hiddenField.value;
						              showSelDialog(p,'depart',function(o){
						            	    Ext.getCmp('dep_ids').setValue(o.vas.join(','));
						            	    Ext.getCmp('dep_ids').hiddenField.value = o.ids.join(',');
								      });
						        }
			                },
			                emptyText:'请指定接收部门...'
			            }
					},{
						columnWidth:.33,
						layout:'form',
						items:{
			               	xtype:'combo',
			                fieldLabel: '接收工作组',
			                id:'pro_ids',
			                store:persDS,
			                displayField:'name',
			                valueField:'id',
			                hiddenName:'proIds',
			                typeAhead: true,
			                forceSelection: true,
			                selectOnFocus:true,
			                mode:'remote',
			                triggerAction: 'all',
			                listeners : {
								'focus':function(node,event){
							          var p = {};
							          p.vas = Ext.getCmp('pro_ids').getValue();
							          p.ids = Ext.getCmp('pro_ids').hiddenField.value;
						              showSelDialog(p,'pro',function(o){
						            	    Ext.getCmp('pro_ids').setValue(o.vas.join(','));
						            	    Ext.getCmp('pro_ids').hiddenField.value = o.ids.join(',');
								      });
						        }
			                },
			                emptyText:'请指定接收工作组...'
			            }
					},{
						columnWidth:.33,
						layout:'form',
						items:{
	                    	xtype:'combo',
	                    	fieldLabel: '接收人',
	                        hiddenName:'staIds',
	                        id:'sta_ids',
	                        store:staffDS,
	                        displayField:'name',
	                        valueField:'id',
	                        typeAhead: true,
	                        forceSelection: true,
	                        selectOnFocus:true,
	                        mode:'remote',
	                        triggerAction: 'all',
	                        width:180,
	                        listeners : {
								'focus':function(node,event){
							          var p = {};
							          p.vas = Ext.getCmp('sta_ids').getValue();
							          p.ids = Ext.getCmp('sta_ids').hiddenField.value;
						              showSelDialog(p,'staff',function(o){
						            	    Ext.getCmp('sta_ids').setValue(o.vas.join(','));
						            	    Ext.getCmp('sta_ids').hiddenField.value = o.ids.join(',');
								      });
						        }
			                },
	                        emptyText:'请指定接收人...'
	                    }
					}]
                },{
		            name:'command.content',
	                id:'command_content',
	                xtype:'textarea',
                    style:{color:'blue','font-size':'18px'},
	                disabled:true,
	                fieldLabel:'内容',
	                height:200,
	                anchor:'98%'
	            },{
				layout:'column',
				items:[{
							columnWidth:.225,
							layout:'form',
							items:{
						        name:'command.issueTime',
						        id:'command_issueTime',
								xtype:'datefield',
								format:'Y-m-d',
								disabled:true,
								fieldLabel:'签发时间'
							}
						},{
							columnWidth:.225,
							layout:'form',
							items:{
								name:'command.sendTime',
								id:'command_sendTime',
								xtype:'datefield',
								format:'Y-m-d',
								disabled:true,
								fieldLabel:'发布时间'
							}
						},{
							columnWidth:.275,
							layout:'form',
							items:[{
		                    	xtype:'combo',
		                    	fieldLabel: '签发人',
		                        hiddenName:'command.issuer.id',
		                        id:'command_issuer_id',
		                        store:staffDS,
		                        displayField:'name',
		                        valueField:'id',
		                        typeAhead: true,
		                        forceSelection: true,
		                        selectOnFocus:true,
		                        mode:'remote',
		                        triggerAction: 'all',
		                        width:130,
		                        disabled:true,
		                        emptyText:'请指定签发人...'
		                    }]
						},{
							columnWidth:.275,
							layout:'form',
							items:[{
		                    	xtype:'combo',
		                    	fieldLabel: '发送人',
		                        hiddenName:'command.sender.id',
		                        id:'command_sender_id',
		                        store:staffDS,
		                        displayField:'name',
		                        valueField:'id',
		                        typeAhead: true,
		                        forceSelection: true,
		                        selectOnFocus:true,
		                        mode:'remote',
		                        triggerAction: 'all',
		                        width:130,
		                        disabled:true,
		                        emptyText:'请指定发送人...'
		                    }]
						}]
            	}
        ]
    });
    
    
    var doClose = function(){
        addDialog.hide();
    }

    var doDoingStatus = function(){
    	 Ext.Msg.confirm('确认', '确认将状态改为【已安排处理】吗？', function(btn){
             if (btn == 'yes'){
                 Ext.Ajax.request({
                    url: 'command/status.action?command.id='+Ext.get('command_id').dom.value+'&command.status=2',
                    success:function(){
                	 		Ext.Msg.alert('我来找茬处理成功','恭喜您成功地将状态改为【已安排处理】！');
                    },
                    failure:function(response,options){
                    	    Ext.Msg.alert('我来找茬处理失败','很遗憾修改状态【已安排处理】失败！');
                    }
                 });
             }
         });
    }
    
    var doOverStatus = function(){
    	 Ext.Msg.confirm('确认', '确认将状态改为【已处理完毕】吗？', function(btn){
             if (btn == 'yes'){
                 Ext.Ajax.request({
                    url: 'command/status.action?command.id='+Ext.get('command_id').dom.value+'&command.status=3',
                    success:function(){
                	 		Ext.Msg.alert('我来找茬处理成功','恭喜您成功地将状态改为【已处理完毕】！');
                    },
                    failure:function(response,options){
                    	    Ext.Msg.alert('我来找茬处理失败','很遗憾修改状态【已处理完毕】失败！');
                    }
                 });
             }
         });
    }
    
    var doAdd = function(){
    	//提交到服务器操作
        simple.form.doAction('submit',{
          url:'command/add.action',//文件路径
          method:'post',//提交方法post或get
          //提交成功的回调函数
          success:function(response,options){
        	  addDialog.hide();
	          Ext.get('command_id').dom.value = '';
	          Ext.Msg.alert('我来找茬转发成功','恭喜您成功地转发了我来找茬！',function(){ds.reload();});
          },
          //提交失败的回调函数
          failure:function(response,options){
        	  Ext.Msg.alert('错误','请检查您的输入是否为空,如果多次确认无法成功请与系统管理员联系!！');
          }
        });
    }
    
    var addDialog;

    var initEditDialog = function(title){
        if(!addDialog){
        	addDialog = new Ext.Window({
     			layout:'fit',
     			width:880,
     			height:400,
     			closeAction:'hide',
     			plain:true,
     			buttons:[{text:'转发',disabled:false,handler:doAdd},{text:'已安排处理',handler:doDoingStatus},{text:'已处理完毕',handler:doOverStatus},{text:'查看附件',disabled:false,handler:showAttDialog}],
     			items:simple
         });
        }
        addDialog.setTitle(title);
    }

    var getSelPros = function(o,name){
        if(o.length<1)return "";
        var res = [];
        for(var i=0;i<o.length;i++){
            res.push(o[i][name]);
        }
        return res.join(',');
    }
    
    function showUser() {
    	var s = grid.getSelectionModel().getSelections();
        if (s.length>1) {
            Ext.Msg.alert('出错啦','您选择了 '+s.length+' 条记录,目前只支持一次查看一条记录！');
            return false;
        }
        if (s.length==0) {
            Ext.Msg.alert('出错啦','你还没有选择要操作的记录！');
            return false;
        }
  	    initEditDialog('查看我来找茬详情');
  	    addDialog.show('showBtn');
  	    
  	    Ext.get('command_id').dom.value = s[0].data.id;  	    
  	    Ext.getCmp('command_sendType').setValue(s[0].data.sendType);
  	    Ext.get('command_top').dom.checked = s[0].data.top=='true'?true:false;
  	    if(s[0].data.imgSrc&&s[0].data.imgSrc!=""){
  	    	showAttDialog["src"] = s[0].data.imgSrc;
  	  	}
  	    Ext.getCmp('command_content').setValue(s[0].data.content);
  	    
  	    Ext.get('command_issueTime').dom.value = s[0].data.issueTime;
  	    Ext.get('command_sendTime').dom.value = s[0].data.sendTime;

  	    Ext.getCmp('command_issuer_id').setValue(s[0].data.issuer.name?s[0].data.issuer.name:"");
	    Ext.getCmp('command_issuer_id').hiddenField.value = s[0].data.issuer.id?s[0].data.issuer.id:"";
  	    Ext.getCmp('command_sender_id').setValue(s[0].data.sender.name?s[0].data.sender.name:"");
	    Ext.getCmp('command_sender_id').hiddenField.value = s[0].data.sender.id?s[0].data.sender.id:"";
	    
	    Ext.getCmp('dep_ids').setValue(getSelPros(s[0].data.deparList,'name'));
  	    Ext.getCmp('dep_ids').hiddenField.value = getSelPros(s[0].data.deparList,'id');
  	    
	    Ext.getCmp('pro_ids').setValue(getSelPros(s[0].data.proList,'name'));
  	    Ext.getCmp('pro_ids').hiddenField.value = getSelPros(s[0].data.proList,'id');
  	    
	    Ext.getCmp('sta_ids').setValue(getSelPros(s[0].data.staffList,'name'));
  	    Ext.getCmp('sta_ids').hiddenField.value = getSelPros(s[0].data.staffList,'id');
         	   
    }
    
    var getIds = function(g){
    	var s = g.getSelectionModel().getSelections();
    	 if (s.length==0) {
             return false;
         }
         var ids = [];
         for(var i=0;i<s.length;i++){
             ids.push(s[i].data.id);
         }
         return ids.join(',');
    }

    var delSucc = function(result){
    	loadList();
    }
    
    function delUser() {
        var ids = getIds(grid);
        if (ids) {
            Ext.Msg.confirm('确认', '真的要删除吗？', function(btn){
                if (btn == 'yes'){
                    Ext.Ajax.request({
                       url: 'command/del.action?commandIds='+ids,
                       success:delSucc
                    });
                }
            });       
        } else {
            Ext.Msg.alert('出错啦','你还没有选择要操作的记录！');
        }
    }

  
    var replyDialog;

    var initReplyDialog = function(title){
        if(!replyDialog){
        	replyDialog = new Ext.Window({
     			layout:'fit',
     			width:500,
     			height:300,
     			closeAction:'hide',
     			modal:true,
     			plain:true,
     			buttons:[{text:'关闭',handler:function(){replyDialog.hide();}}],
     			items:replyGrid
         });
        }
        replyDialog.setTitle(title);
    }
    
   function shwoReply(){
	   var s = grid.getSelectionModel().getSelections();
       if (s.length>1) {
           Ext.Msg.alert('出错啦','您选择了 '+s.length+' 条记录,目前只支持一次查看一条指令的回复！');
           return false;
       }
       if (s.length==0) {
           Ext.Msg.alert('出错啦','你还没有选择要查看回复的指令！');
           return false;
       }
       
       replyDS.on('beforeload',function(){
           Ext.apply(this.baseParams,{
               'command.id':s[0].data.id
           });
       });
       
	   replyDS.load({params:{'start':0,'limit':20,'command.id':s[0].data.id},callback:function(r,options,success){
		    if(!success){//没取到数据时返回的success=false
		    	replyGrid.store.removeAll();//清除原有数据
		  }
	   }});
	   
       initReplyDialog("["+s[0].data.id+"]的回复");
       replyDialog.show("replyBtn");
   } 

var getMDialog = function(mData,type,fn,p){
       
       var getMHTML = function(d,sis){
         var ids = {};	
         if(sis&&sis.ids){
             var sids = sis.ids.split(',');
             for(var i=0;i<sids.length;i++){
           	  ids[sids[i]] = true;
             }
         }
         var res = [];
         res.push( '<table style="width:100%;text-align:left;margin-top:10px;"><tr style="border-bottom:1px solid blue"><td colspan="2"><input id="'+type+'_sel"></input></td><td> 全选 &nbsp;&nbsp;<input type="checkbox" id="'+type+'_selAll"></input></td></tr>');
         for(var i=0;i<d.length;i+=4){
               res.push('<tr>');
               for(var j=0;j<4;j++){
                   var index = i+j; 
                   var cstr =  d[index]&&d[index].id&&ids[d[index].id]?' checked = "checked" ':"";
                   var c = d[index]&&d[index].id?'<input type="checkbox" name="'+type+'_xx" value="'+d[index].id+'" dname="'+d[index].name+'" '+cstr+'> '+d[index].name:'';
                   res.push('<td>'+c+'</td>'); 
               }
               res.push('</tr>');
         }
         res.push('</table>');
         return res.join('');
       }        

        var doClose = function(){
            getMDialog[type].hide();
            addDialog.show();
        }

        var doSel = function(){
          getMDialog[type].hide();
          var cs = document.getElementsByName(type+'_xx');
          var o = {};
          o.ids = [];
          o.vas = [];
          for(var i=0;i<cs.length;i++){
              if(cs[i].checked){
                  o.ids.push(cs[i].value);
                  o.vas.push(cs[i].getAttribute('dname'));
              }
          }
          if(fn)fn(o);
          addDialog.show();
        }

        var selAll = function(t){
        	var cs = document.getElementsByName(type+'_xx');
        	for(var i=0;i<cs.length;i++){
                    cs[i].checked = t;
            }
        }
        
        var likeSel = function(v){
        	var cs = document.getElementsByName(type+'_xx');
        	for(var i=0;i<cs.length;i++){
                if(cs[i].getAttribute('dname').indexOf(v)!=-1){
                    cs[i].checked = true;
                }else{
                    cs[i].checked = false;
                }
            }
        }
        
        if(!getMDialog[type]){
             getMDialog[type] = new Ext.Window({
                     layout:'fit',
                     width:500,
                     height:300,
                     closeAction:'hide',
                     modal:true,
                     plain:true,
                     buttons:[{text:'确认',disabled:false,handler:doSel},{text:'关闭',handler:doClose}],
                     html:'<div style="width:100%;height:100%;overflow-y:auto;" id = "'+type+'_dialog_div">'+getMHTML(mData,p)+'</div>' 
              });
        }else{
       	 	document.getElementById(type+'_dialog_div').innerHTML = getMHTML(mData,p);
        }
        getMDialog[type].show();
        document.getElementById(type+'_sel').onkeyup = function(){
        	likeSel(this.value);
        }
        document.getElementById(type+'_selAll').onclick = function(){
        	selAll(this.checked);
        }
    }

    var showSelDialog = function(p,type,fn){
   	 addDialog.hide();
   	 var mk = new Ext.LoadMask(document.body, {
   		 msg: '正在获取数据，请稍候!',
   		 removeMask: true //完成后移除
   	 });
   	 mk.show();
	     Ext.Ajax.request({
	     		url: 'polling/list.action',
	   			params: {
	    	 		tType:type,
	   			},
	     	 	success: function(response, options) {
	   			var mData = Ext.util.JSON.decode(response.responseText);                                             
	     			if(mData&&mData.topics){
		     			mk.hide();
	     			    var dialog = getMDialog(mData.topics,type,fn,p);  
	     			}
	     		},
	            failure:function(response,options){
	     		  mk.hide();
	          	  Ext.Msg.alert('错误','请检查您的输入是否为空,如果多次确认无法成功请与系统管理员联系!！');
	            }
	 	 });
    }

    var showAttDialog = function(){
        if(showAttDialog["src"]&&showAttDialog["src"]!=""&&showAttDialog["src"].length>5){
	        if(!showAttDialog["dialog"]){
	        	showAttDialog["dialog"] = new Ext.Window({
	                layout:'fit',
	                width:500,
	                height:300,
	                closeAction:'hide',
	                modal:true,
	                plain:true,
	                buttons:[{text:'确认',handler:function(){showAttDialog["dialog"].hide();}}],
	                html:'<img GALLERYIMG="no" id="_showAttDialog" style="width:100%;height:100%;overflow-y:auto;" src="">' 
	         }); 
	        }
	        showAttDialog["dialog"].show();
	        document.getElementById("_showAttDialog").src = showAttDialog["src"];
        }else{
        	Ext.Msg.alert('错误','该信息无附件');
        }
    }

    window._showAttDialog = function(src){
        if(src&&src!=""&&src.length>5){
	        if(!window._showAttDialog["dialog"]){
	        	window._showAttDialog["dialog"] = new Ext.Window({
	                layout:'fit',
	                width:500,
	                height:300,
	                closeAction:'hide',
	                modal:true,
	                plain:true,
	                buttons:[{text:'确认',handler:function(){ document.getElementById("_showAttDialog").src = "";window._showAttDialog["dialog"].hide();}}],
	                html:'<img id="_showAttDialog" GALLERYIMG="no" style="width:100%;height:100%;overflow-y:auto;" src="">' 
	         }); 
	        }
	        window._showAttDialog["dialog"].show();
	        document.getElementById("_showAttDialog").src = src;
        }else{
        	Ext.Msg.alert('错误','该信息无附件');
        }
    }
});
</script>
</body>
</html>